package com.hzncc.flowable_diboot.project_contracts.dto;

import com.diboot.core.binding.query.BindQuery;
import com.diboot.core.binding.query.Comparison;
import com.hzncc.flowable_diboot.entity.SapCustomer;
import com.hzncc.flowable_diboot.project_contracts.entity.ProjectContractAudit;
import com.hzncc.flowable_diboot.project_contracts.entity.ProjectContractCancel;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * 项目类合同取消 DTO定义
 *
 * @author MyName
 * @version 1.0
 * @date 2024-09-24
 * Copyright © MyCorp
 */
@Getter
@Setter
@Accessors(chain = true)
public class ProjectContractCancelDTO extends ProjectContractCancel {
    private static final long serialVersionUID = 1845794076472609520L;

    /**
     * 采购订单编号 关联信息
     */
    @BindQuery(entity = ProjectContractAudit.class, column = "contractCode", condition = "this.contractId = id")
    private String contractCode;
    /**
     * 客户名称 关联信息
     */
    @BindQuery(entity = SapCustomer.class, column = "name", condition = "this.customerId = id")
    private String customerName;
    /**
     * 申请日期
     */
    @BindQuery(comparison = Comparison.GE)
    private LocalDateTime applicationDate;
    /**
     * 申请日期 起始
     */
    @BindQuery(comparison = Comparison.GE, column = "application_date")
    private LocalDate applicationDateBegin;

    /**
     * 申请日期 截止
     */
    @BindQuery(comparison = Comparison.LT, column = "application_date")
    private LocalDate applicationDateEnd;
    /**
     * 创建时间
     */
    @BindQuery(comparison = Comparison.GE)
    private LocalDateTime createTime;
    /**
     * 创建时间 起始
     */
    @BindQuery(comparison = Comparison.GE, column = "create_time")
    private LocalDate createTimeBegin;

    /**
     * 创建时间 截止
     */
    @BindQuery(comparison = Comparison.LT, column = "create_time")
    private LocalDate createTimeEnd;
    /**
     * 更新时间
     */
    @BindQuery(comparison = Comparison.GE)
    private LocalDateTime updateTime;
    /**
     * 更新时间 起始
     */
    @BindQuery(comparison = Comparison.GE, column = "update_time")
    private LocalDate updateTimeBegin;

    /**
     * 更新时间 截止
     */
    @BindQuery(comparison = Comparison.LT, column = "update_time")
    private LocalDate updateTimeEnd;

    public LocalDate getApplicationDateEnd() {
        if (getApplicationDate() != null) {
            return getApplicationDate().plusDays(1).toLocalDate();
        }
        if (applicationDateEnd != null) {
            return applicationDateEnd.plusDays(1);
        }
        return null;
    }

    public LocalDate getCreateTimeEnd() {
        if (getCreateTime() != null) {
            return getCreateTime().plusDays(1).toLocalDate();
        }
        if (createTimeEnd != null) {
            return createTimeEnd.plusDays(1);
        }
        return null;
    }

    public LocalDate getUpdateTimeEnd() {
        if (getUpdateTime() != null) {
            return getUpdateTime().plusDays(1).toLocalDate();
        }
        if (updateTimeEnd != null) {
            return updateTimeEnd.plusDays(1);
        }
        return null;
    }

}